<?php
class Admin_Model_Newsitem extends Zend_Db_Table_Abstract
{
    protected $_name = 'news_item';
    
    public function getAllData(){
		$modelNewsCat=new Admin_Model_Newscat();
        $cols=$modelNewsCat->info(Zend_Db_Table_Abstract::COLS);                
        foreach($cols as $col){            
            $newsCatCols[]=$col.' as newsCat_'.$col;
        }        
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('i'=>$this->_name),array('i.itemId','i.catId','i.itemCode','i.itemName','i.shortName','i.ord','i.display','i.highlight'))
                        ->join(array('c'=>'news_cat'),"i.catId = c.catId",$newsCatCols);
        $kq=$this->fetchAll($query);                                                      
        return $this->fetchAll($query);
    }
    public function getDataByItemId($itemId){
		$query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('i'=>$this->_name),array('i.itemId','i.itemCode','i.itemName','i.shortName','i.ord','i.display'))
                        ->join(array('c'=>'news_cat'),"i.catId = c.catId",array('c.catId','c.catCode','c.catName','c.shortName','c.ord','c.display'))
                        ->where('i.itemId = ?',(int)$itemId);
        return $this->fetchRow($query);
    }
    public function getDataByCatId($catId){
		$query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('i'=>$this->_name),array('i.itemId','i.itemCode','i.itemName','i.shortName','i.ord','i.display'))
                        ->join(array('c'=>'news_cat'),"i.catId = c.catId",array('c.catId','c.catCode','c.catName','c.shortName','c.ord','c.display'))
                        ->where('c.catId = ?',(int)$catId);
        return $this->fetchAll($query);
    }      
    public function updateItem($data,$itemId){
        $this->update($data,"itemId=$itemId");          
    }
    
    
    
}

